package com.sky.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sky.entity.Category;
import com.sky.entity.Employee;
import com.sky.mapper.CategoryMapper;
import com.sky.result.PageResult;
import com.sky.service.CategoryService;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class CategoryServiceImpl  implements CategoryService {


    @Autowired
    private CategoryMapper categoryMapper;

    //分类分页查询
    @Override
    public PageResult page(String name, int page, int pageSize, Integer type) {

        // 设置分页参数
        PageHelper.startPage(page, pageSize);

        if (StringUtils.hasText(name)) {
            name = "%" + name + "%";
        }
        // 执行分页查询
        List<Category> empList = categoryMapper.list(name,type);
        // 获取分页结果
        Page<Category> p = (Page<Category>) empList;
        //封装PageBean
        PageResult pageResult = new PageResult(p.getTotal(), p.getResult());

        return pageResult;
    }

    //修改
    @Override
    public Integer updateCate(Category category) {
        return categoryMapper.updateCate(category);
    }


    //启用、禁用分类
    @Override
    public void upstatus(Integer status, Long id) {
       Category category = new Category();
       category.setId(id);
       category.setStatus(status);
       categoryMapper.updatus(category);

    }

    //新增分类
    @Override
    public Integer save(Category category) {

        return categoryMapper.save(category);
    }

    //删除分类
    @Override
    public Integer remove(Long id) {

        Integer cont = categoryMapper.remove(id);
        return cont;
    }

    //根据类型查询分类
    @Override
    public List<Category> getByType(Integer type) {

        return categoryMapper.getByType(type);
    }

// 查询所有套餐分类
    @Override
    public List<Category> getAll() {
        return categoryMapper.selectAll();
    }


}
